home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 June: Reference Library / Dev.CD Jun 99 RL Disk 1.toast / What's New / Development Kits / Mac_OS_USB_DDK_v1.2 / Examples / USBModem / ShimSerialStub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-15  |  4.9 KB  |  184 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ShimSerialStub.c
  3.  
  4.     Contains:    Routines used to insterface to the shim
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.  
  9.     
  10.     Copyright:    © 1996-1998 by Apple Computer, Inc., all rights reserved.
  11.  
  12.  
  13. */
  14.  
  15. #include <Errors.h>
  16. #include <LowMem.h>
  17. #include <TextUtils.h>
  18.  
  19. #include "Modem.h"
  20. #include "ShimSerialStub.h"
  21.  
  22. //
  23. //    Statically define the Icon & Icon Mask for
  24. //    the CRM structures.  In the new world 
  25. //    (this was Rhapsody) we don't have resources 
  26. //    so we have to do it the hard way.
  27. //    This doesn't make sense anymore we should
  28. //    change this to support resource based icons
  29. //
  30.  
  31. UInt32 CRMDeviceIcon[] = {
  32.     0xFFFFFFFF, 0x80000001, 0x80018001, 0x80018001,
  33.     0x80024001, 0x80042001, 0x80042001, 0x80081001,
  34.     0x800E7001, 0x80024FC1, 0x80C24841, 0x81224841,
  35.     0x82124841, 0x82124CC1, 0x82124501, 0x81224901,
  36.     0x80A25201, 0x80926401, 0x804A0801, 0x80261001,
  37.     0x80102001, 0x80084001, 0x80044001, 0x80024001,
  38.     0x80042001, 0x80081001, 0x80081001, 0x80081001,
  39.     0x80042001, 0x8003C001, 0x80000001, 0xFFFFFFFF,
  40.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  41.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  42.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  43.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  44.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  45.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  46.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  47.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
  48. };
  49.  
  50. /***********************************************************************************/
  51. //    Function:        InstallShimDrvr(CFragConnectionID    ConnID)
  52. //    Description:    Handles the interface with the shim install
  53. //
  54. //    Input:            CFrag Connection ID (mine)
  55. //    Output:            Results
  56. /***********************************************************************************/
  57.  
  58. OSErr InstallShimDrvr(CFragConnectionID    ConnID)
  59. {
  60.     OSErr                 err;
  61.     SerialShimInterface    IntBlk;
  62.     
  63.     TraceMessage(0, "\pEntering InstallShimDrvr");
  64.     
  65.     err = LoadShim();
  66.     if (err == noErr)
  67.     {    
  68.         IntBlk.DRVRInName = kDRVRInName;
  69.         IntBlk.DRVROutName = kDRVROutName;
  70.         IntBlk.CRMName = kCRMName;
  71.         IntBlk.CRMIcon = (IconPtr)&CRMDeviceIcon;
  72.         IntBlk.MaxSpeed = kMaxBaudRate;
  73.         IntBlk.RefCon = 0;
  74.         IntBlk.ConnID = ConnID;
  75.         err = (*gGlobals->ShimInstall) (IntBlk, &gGlobals->ShimRef);
  76.     }
  77.     
  78.     return err;
  79. }
  80.  
  81. /***********************************************************************************/
  82. //    Function:        RemoveShimDrvr(Boolean forceFlag)
  83. //    Description:    Handles the interface with the shim remove
  84. //
  85. //    Input:            Orderly or forced
  86. //    Output:            Results
  87. /***********************************************************************************/
  88.  
  89. OSErr RemoveShimDrvr(Boolean forceFlag)
  90. {    
  91.     OSErr     err;
  92.     
  93.     TraceMessage(0, "\pEntering RemoveShimDrvr");
  94.     
  95.     if (gGlobals->ShimRef != kInvalidRef)
  96.     {
  97.         err = (*gGlobals->ShimRemove) (gGlobals->ShimRef, forceFlag);
  98. //        if (err == noErr)
  99. //            UnLoadShim();
  100.     }
  101.     
  102.     return err;
  103. }
  104.  
  105. /***********************************************************************************/
  106. //    Function:        LoadShim
  107. //    Description:    Loads the shim and sets up the various addresses
  108. //
  109. //    Input:            Nothing
  110. //    Output:            Results
  111. /***********************************************************************************/
  112.  
  113. OSErr LoadShim(void)
  114. {
  115.     OSErr                err = noErr;            // Let's assume success
  116.     Ptr                    FragAddr;
  117.     CFragConnectionID    ConnID;
  118.     Str255                errMsg;
  119.     CFragSymbolClass    cClass;
  120.     
  121.     err = GetSharedLibrary("\pSerialShimLib", kPowerPCCFragArch, kLoadCFrag, &ConnID, &FragAddr, errMsg);
  122.     if (err == noErr)
  123.     {
  124.         gGlobals->ConnID = ConnID;
  125.         err = FindSymbol(ConnID, "\pSerialShimInstallDriver", (Ptr *)&gGlobals->ShimInstall, &cClass);
  126.         if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  127.         {
  128.             err = -1;
  129.         }
  130.         
  131.         if (err == noErr)
  132.         {
  133.             err = FindSymbol(ConnID, "\pSerialShimRemoveDriver", (Ptr *)&gGlobals->ShimRemove, &cClass);
  134.             if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  135.             {
  136.                 err = -1;
  137.             }
  138.         }
  139.         
  140.         if (err == noErr)
  141.         {
  142.             err = FindSymbol(ConnID, "\pSerialShimIOComplete", (Ptr *)&gGlobals->ShimComplete, &cClass);
  143.             if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  144.             {
  145.                 err = -1;
  146.             }
  147.         }
  148.     }
  149.  
  150.     return err;
  151. }
  152.  
  153. /***********************************************************************************/
  154. //    Function:        UnLoadShim
  155. //    Description:    UnLoads the shim, actually closes the connection
  156. //
  157. //    Input:            Nothing
  158. //    Output:            Results
  159. /***********************************************************************************/
  160.  
  161. OSErr UnLoadShim(void)
  162. {
  163.     OSErr    err = noErr;            // Let's assume success
  164.     
  165.     err = CloseConnection(&gGlobals->ConnID);
  166.     
  167.     return err;
  168.  
  169. }
  170.  
  171. /***********************************************************************************/
  172. //    Function:        ShimIOComplete
  173. //    Description:    Sets up and calls the shim's completion routine
  174. //
  175. //    Input:            Parameter block and result code
  176. //    Output:            nothing
  177. /***********************************************************************************/
  178.  
  179. void     ShimIOComplete(ParmBlkPtr pb, OSErr result)
  180. {
  181.     pb->ioParam.ioResult = result;
  182.     (*gGlobals->ShimComplete) (gGlobals->ShimRef, (IOParam *)pb);
  183.  
  184. }